home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / EXAMP11.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.4 KB  |  49 lines

  1. rem 
  2. rem $Header: examp11.sql 7020100.1 94/09/28 16:39:55 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      examp11.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     rvasired   05/12/92 -  Creation 
  15. /*
  16. ** This block calculates the ratio between the X and Y columns of
  17. ** the RATIO table.  If the ratio is greater than 0.72, the block
  18. ** inserts the ratio into RESULT_TABLE.  Otherwise, it inserts -1.
  19. ** If the denominator is zero, ZERO_DIVIDE is raised, and a
  20. ** zero is inserted into RESULT_TABLE.
  21. **
  22. ** Copyright (c) 1989,1992 by Oracle Corporation
  23. */
  24.  
  25. DECLARE
  26.     numerator    NUMBER;
  27.     denominator  NUMBER;
  28.     the_ratio    NUMBER;
  29.     lower_limit  CONSTANT NUMBER := 0.72;
  30.     samp_num     CONSTANT NUMBER := 132;
  31. BEGIN
  32.     SELECT x, y INTO numerator, denominator FROM result_table
  33.         WHERE sample_id = samp_num;
  34.     the_ratio := numerator/denominator;
  35.     IF the_ratio > lower_limit THEN
  36.         INSERT INTO ratio VALUES (samp_num, the_ratio);
  37.     ELSE
  38.         INSERT INTO ratio VALUES (samp_num, -1);
  39.     END IF;
  40.     COMMIT;
  41. EXCEPTION
  42.     WHEN ZERO_DIVIDE THEN
  43.         INSERT INTO ratio VALUES (samp_num, 0);
  44.         COMMIT;
  45.     WHEN OTHERS THEN
  46.         ROLLBACK;
  47. END;
  48. /
  49.